package com.baoyouqun.controller.back;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.InvoiceOrderRelCreateCmd;
import com.baoyouqun.domain.Query.InvoiceOrderRelQuery;
import com.baoyouqun.domain.UpdateCmd.InvoiceOrderRelUpdateCmd;
import com.baoyouqun.domain.VO.InvoiceOrderRelVO;
import com.baoyouqun.service.InvoiceOrderRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/back/invoiceOrderRel")
@Api(tags = "发票与订单关联表（一个发票关联多个订单）管理接口")
public class InvoiceOrderRelController {

    @Resource
    private InvoiceOrderRelService invoiceOrderRelService;

    @PostMapping("create")
    @ApiOperation("新增发票与订单关联表（一个发票关联多个订单）")
    public SingleResponse<InvoiceOrderRelVO> create(InvoiceOrderRelCreateCmd cmd) {
        return invoiceOrderRelService.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改发票与订单关联表（一个发票关联多个订单）")
    public Response update(InvoiceOrderRelUpdateCmd cmd) {
        return invoiceOrderRelService.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除发票与订单关联表（一个发票关联多个订单）")
    public Response delete(String id) {
        StpUtil.checkRole("R010000");
        invoiceOrderRelService.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询发票与订单关联表（一个发票关联多个订单）")
    public SingleResponse<InvoiceOrderRelVO> selectById(String id) {
        return SingleResponse.of(invoiceOrderRelService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询发票与订单关联表（一个发票关联多个订单）")
    public PageResponse<InvoiceOrderRelVO> page(InvoiceOrderRelQuery query) {
        IPage<InvoiceOrderRelVO> page = invoiceOrderRelService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}